package com.primaryedu.adapter;

import java.util.ArrayList;
import java.util.List;

import com.primaryedu.R;
import com.primaryedu.bean.ClassBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 课务调整数据适配器
 *
 * @author jun.wang
 * @description
 * @data 2017年12月11日
 */
public class ClassAdjustAdapter extends BaseAdapter {

    private Context context;
    LayoutInflater inflater;
    private List<ClassBean> list = new ArrayList<>();

    public ClassAdjustAdapter(Context context, List<ClassBean> list) {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void updateView(List<ClassBean> nowList) {
        this.list = nowList;
        this.notifyDataSetChanged();//强制动态刷新数据进而调用getView方法
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (null == convertView) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_class_adjust, null);
            viewHolder.text_classname = (TextView) convertView.findViewById(R.id.text_classname);
            viewHolder.text_name = (TextView) convertView.findViewById(R.id.text_name);
            viewHolder.text_subject = (TextView) convertView.findViewById(R.id.text_subject);
            viewHolder.text_date = (TextView) convertView.findViewById(R.id.text_date);
            viewHolder.text_pitch = (TextView) convertView.findViewById(R.id.text_pitch);
            viewHolder.text_remark = (TextView) convertView.findViewById(R.id.text_remark);
            viewHolder.image = (ImageView) convertView.findViewById(R.id.image);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        ClassBean bean = list.get(position);
        viewHolder.text_classname.setText("班级：" + bean.getClassname());
        viewHolder.text_name.setText("教师姓名：" + bean.getTeacher());
        viewHolder.text_subject.setText("学科：" + bean.getSubject());
        viewHolder.text_date.setText("日期：" + bean.getWeek());
        viewHolder.text_pitch.setText("节：" + bean.getLesson());
        viewHolder.text_remark.setText(bean.getRemarks());
        if (bean.getStatus().equals("1")) {//未处理
            viewHolder.image.setBackgroundResource(R.drawable.leave_no_deal);
        } else if (bean.getStatus().equals("2") || bean.getStatus().equals("3")) {//审核通过或者不通过
            viewHolder.image.setBackgroundResource(R.drawable.leave_deal);
        }


        return convertView;
    }

    class ViewHolder {
        TextView text_classname;
        TextView text_name;
        TextView text_subject;
        TextView text_date;
        TextView text_pitch;
        TextView text_remark;
        ImageView image;
    }

}
